[BITS 32]
[SECTION .text]

; <summary>
; void clRGBA32ToARGB32(void *buffer, unsigned int count)
; </summary>
[GLOBAL clRGBA32ToARGB32]
clRGBA32ToARGB32:
	push ebp
	mov ebp, esp
	mov eax, [ebp+8]
	mov ebx, [ebp+12]
	shr ebx, 4 ; count = count / 16
	movdqa xmm0, [eax]

	pop ebp
	emms
	ret

; <summary>
; void clBGRA32ToRGBA32(void *buffer, unsigned int count)
; </summary>
[GLOBAL clBGRA32ToRGBA32]
clBGRA32ToRGBA32:
	push ebp
	mov ebp, esp
	mov ecx, [ebp+8]
	mov edx, [ebp+12]
	add	edx, 3
	sar	edx, 2
	run:
	; <pixel>
	;movdqa xmm0, [ecx]
	;movdqa [ecx], xmm0

		
	mov al, [ecx+0]
	mov ah, [ecx+2]
	mov [ecx+2], al
	mov [ecx+0], ah
	; </pixel>
	add ecx, 4
	dec edx
	jnz run
	mov eax, edx
	mov esp, ebp
	pop ebp
	emms
	ret



; <summary>
; void clBGRAFloatToRGBAFloat(void *buffer, unsigned int count)
; </summary>
[GLOBAL clBGRAFloatToRGBAFloat]
clBGRAFloatToRGBAFloat:
	push ebp
	mov ebp, esp
	mov ecx, [ebp+8]
	mov edx, [ebp+12]
	run_0:
	movups xmm0, [ecx]
	pshufd xmm0, xmm0, 0xC6
	movups [ecx], xmm0
	add ecx, 16
	dec edx
	jnz run_0
	mov eax, edx
	mov esp, ebp
	pop ebp
	emms
	ret

; <summary>
; void clRGBAFloatToBGRAFloat(void *buffer, unsigned int count)
; </summary>
[GLOBAL clRGBAFloatToBGRAFloat]
clRGBAFloatToBGRAFloat:
	push ebp
	mov ebp, esp
	mov ecx, [ebp+8]
	mov edx, [ebp+12]
	run_1:
	movups xmm0, [ecx]
	pshufd xmm0, xmm0, 0xC6
	movups [ecx], xmm0
	add ecx, 16
	dec edx
	jnz run_1
	mov eax, edx
	mov esp, ebp
	pop ebp
	emms
	ret
	
; <summary>
; void clRGBAFloatToARGBFloat(void *buffer, unsigned int count)
; </summary>
[GLOBAL clRGBAFloatToARGBFloat]
clRGBAFloatToARGBFloat:
	push ebp
	mov ebp, esp
	mov ecx, [ebp+8]
	mov edx, [ebp+12]
	run_2:
	movups xmm0, [ecx]
	pshufd xmm0, xmm0, 0x93
	movups [ecx], xmm0
	add ecx, 16
	dec edx
	jnz run_2
	mov eax, edx
	mov esp, ebp
	pop ebp
	emms
	ret
